package com.v5.mr.partition;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


/**
 * 分区
 *
 */
public class EmpPartitionMain {

	public static void main(String[] args) throws Exception {
		// 创建一个任务job = map + reduce
		Job job = Job.getInstance(new Configuration());
		//指定任务的入口
		job.setJarByClass(EmpPartitionMain.class);
		
		//指定任务的Map和输出的数据类型
		job.setMapperClass(EmpPartionMapper.class);
		job.setMapOutputKeyClass(LongWritable.class);//员工号
		job.setMapOutputValueClass(Employee.class);//员工对象
		
		//设置任务的分区规则
		job.setPartitionerClass(MyEmployeePartitioner.class);
		//指定分区的个数
		job.setNumReduceTasks(3);
		
		
		//指定任务的Reduce和输出的数据类型
		job.setReducerClass(EmpPartionReducer.class);
		job.setOutputKeyClass(LongWritable.class);//员工号
		job.setOutputValueClass(Employee.class); // 员工对象
		
		//指定输入和输出的HDFS路径
		FileInputFormat.setInputPaths(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		
		//提交任务
		job.waitForCompletion(true);

	}

}
